<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
	<meta charset="utf-8">
	<meta name="csrf-token" content="{{ csrf_token() }}">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>个人主页</title>
	<link rel="stylesheet" href="{{URL::asset('vendor/laravel-admin/font-awesome/css/font-awesome.min.css')}}">
	<link rel="stylesheet" href="{{URL::asset('vendor/laravel-admin/AdminLTE/bootstrap/css/bootstrap.min.css')}}">
	<link rel="stylesheet" href="{{URL::asset('vendor/element-ui/lib/theme-chalk/index.css')}}">
	<link rel="stylesheet" href="{{URL::asset('vendor/element-ui/lib/theme-chalk/reset.style.css')}}">
	<link rel="stylesheet" href="{{URL::asset('css/consultation/register.css')}}">
	<script src="{{URL::asset('js/jquery.min.js')}}"></script>
	<script src="{{URL::asset('vendor/element-ui/ext/vue.js')}}"></script>
	<script src="{{URL::asset('vendor/element-ui/lib/index.js')}}"></script>
</head>
<body style="padding:30px;background-color:#F3F3F4;">
<div id="main">
	<el-dialog title="全体学生" :visible.sync="show_st_list" width="90%">
		<el-form :inline="true" :model="seaForm" class="demo-form-inline">
			<el-form-item>
				<el-input v-model="seaForm.name" placeholder="姓名" size="small" clearable>
				</el-input>
			</el-form-item>
			<el-form-item>
				<el-input v-model="seaForm.primary_phone" placeholder="联系方式" size="small" clearable>
				</el-input>
			</el-form-item>
			<el-form-item>
				<el-button type="primary" size="small" @click="getStList">查询</el-button>
			</el-form-item>
		</el-form>
		<el-table :data="st_list_data" v-loading="st_list_loading">
			<el-table-column align="center" property="name" label="姓名"></el-table-column>
			<el-table-column align="center" property="sex" label="性别"></el-table-column>
			<el-table-column align="center" property="age" label="年龄"></el-table-column>
			<el-table-column align="center" property="primary_phone" label="联系方式"></el-table-column>
			<el-table-column align="center" property="primary_parent_name" label="家长姓名"></el-table-column>
			<el-table-column align="center" property="step" label="阶段"></el-table-column>
			<el-table-column align="center" property="status" label="状态"></el-table-column>
			<el-table-column align="center" property="enroll_time" label="入学时间"></el-table-column>
			<el-table-column align="center" label="选择">
				<template slot-scope="scope">
					<el-button type="primary" plain circle size="mini"
						icon="fa fa-check" @click="selectST(scope.row)">
					</el-button>
	  			</template>
			</el-table-column>
		</el-table>
		<el-pagination
			align="right"
			@size-change="pageSizeChange"
			@current-change="curPageChange"
			:current-page="seaForm.page.pageNumber"
			:page-sizes="[10, 25, 50]"
			:page-size="seaForm.page.pageSize"
			layout="total, sizes, prev, pager, next, jumper"
			:total="seaForm.page.total">
		</el-pagination>
	</el-dialog>

	<el-dialog title="编辑家长信息" :visible.sync="show_other_form" width="450px">
		<el-form ref="other_parent" :model="other_form" :rules="parent_rules" label-width="120px">
			<el-form-item label="姓名" prop="name">
				<el-input v-model="other_form.name"></el-input>
			</el-form-item>
			<el-form-item label="联系方式" prop="phone">
				<el-input v-model="other_form.phone"></el-input>
			</el-form-item>
			<el-form-item label="身份证" prop="id_card">
				<el-input v-model="other_form.id_card"></el-input>
			</el-form-item>
			<el-form-item label="亲属关系" prop="relation">
				<el-select v-model="other_form.relation" filterable>
					<el-option label="父亲" value="父亲"></el-option>
					<el-option label="母亲" value="母亲"></el-option>
					<el-option label="其他" value="其他"></el-option>
				</el-select>
			</el-form-item>
			<el-form-item label="是否为主要家长">
				<el-radio v-model="other_form.is_primary" label="0" :disabled="primary_disabled">非主要</el-radio>
  				<el-radio v-model="other_form.is_primary" label="1">主要</el-radio>
			</el-form-item>
		</el-form>
		<p align="right">
			<el-button size="small" @click="show_other_form = false">取消</el-button>
		    <el-button size="small" plain type="success" @click="submitEdit">提交</el-button>
		</p>
	</el-dialog>

	<el-card class="el-card-box">
		<el-collapse>
			<el-collapse-item>
				<template slot="title">
					<h4>历史工单</h4>
				</template>
				<div class="el-card-body">
					<table class="table table-bordered">
						<thead>
							<tr>
								<th class="text-center">序号</th>
								<th class="text-center">日期</th>
								<th class="text-center">咨询方式</th>
								<th class="text-center">工单类型</th>
								<th class="text-center">二级分类</th>
								<th class="text-center">亲属关系</th>
								<th class="text-center">下一步处理</th>
								<th class="text-center">预计回访时间</th>
								<th class="text-center">定级变更</th>
								<th class="text-center">态度描述</th>
								<th class="text-center">备注信息</th>
							</tr>
						</thead>
						<tbody>
							@foreach ($WorkOrders as $k => $order)
							<tr align="center">
								<td>{{$k+1}}</td>
								<td>{{$order['date']}}</td>
								<td>{{$order['ask_way']}}</td>
								<td>{{$order['ask_type']}}</td>
								<td>{{$order['ask_type_s']}}</td>
								<td>{{$order['relation']}}</td>
								<td>{{$order['next_step']}}</td>
								<td>{{$order['expect_revisit']}}</td>
								<td>{{$order['level_changed']}}</td>
								<td>{{$order['attitude_opts']}}</td>
								<td>{{$order['remark']}}</td>
							</tr>
							@endforeach
							@if(empty($WorkOrders))
							<tr align="center">
								<td colspan="11">暂无数据</td>
							</tr>
							@endif
						</tbody>
					</table>
					<h4>定级修改记录:</h4>
					<ul class="list-group" style="width:50%;">
						<li class="list-group-item" v-for="lvl in st_form.lvl_log">@{{lvl}}</li>
					</ul>
				</div>
			</el-collapse-item>
		</el-collapse>
	</el-card>
	<el-row :gutter="15">
		<div class="pull-left el-card-box-left">
			<el-card class="el-card-box">
				<div slot="header" class="el-card-header">
					<h4>学员信息</h4>
					<el-button type="primary" size="small" @click="showStList">选择学生</el-button>
				</div>
				<div class="el-card-body">
					<el-form ref="st_form" :model="st_form" :rules="st_rules" label-width="80px" inline class="st-form pull-left">
						<el-form-item label="家长定级" prop="level">
							<el-input  v-model="st_form.level" disabled></el-input>
						</el-form-item>
						<el-form-item label="姓名" prop="name">
							<el-input v-model="st_form.name"></el-input>
						</el-form-item>
						<el-form-item label="生日" prop="birthday">
							<el-date-picker
								v-model="st_form.birthday"
								type="date"
      							value-format="yyyy-MM-dd"
								placeholder="请选择出生日期">
						    </el-date-picker>
						</el-form-item>
						<el-form-item label="报名时间">
							<el-input  v-model="st_form.enroll_at" disabled></el-input>
						</el-form-item>
						<el-form-item label="性别" prop="sex">
							<el-radio-group v-model="st_form.sex">
								<el-radio label="男"></el-radio>
								<el-radio label="女"></el-radio>
							</el-radio-group>
						</el-form-item><br>
						<el-form-item label="在学阶段" prop="school_info.stage">
							<el-select v-model="st_form.school_info.stage" placeholder="请选择在学阶段" @change="handleSelectStage">
								<el-option label="未入学" value="0"></el-option>
								<el-option label="小学（包括5年制）" value="1"></el-option>
								<el-option label="初中" value="2"></el-option>
								<el-option label="高中/职高" value="3"></el-option>
								<el-option label="其他" value="4"></el-option>
						    </el-select>
						</el-form-item>
						<el-form-item label="年制" :class="special_class">
							<el-radio-group v-model="st_form.school_info.special" @change="handleSelectSpecial">
								<el-radio label="0">六年制</el-radio>
								<el-radio label="1">五年制</el-radio>
							</el-radio-group>
						</el-form-item>
						<el-form-item label="年级" prop="school_info.grade">
							<el-select v-model="st_form.school_info.grade" placeholder="年级">
								<el-option v-for="item in grade_opt" :label="item.label" :value="item.val" :key="item.val"></el-option>
						    </el-select>
						</el-form-item><br>
						<el-form-item label="在读学校" prop="school_info.school">
							<el-select v-model="st_form.school_info.city" filterable placeholder="市">
								<el-option label="昆明市" value="1"></el-option>
								<el-option label="其他" value="0"></el-option>
						    </el-select><br>
							<el-select v-model="st_form.school_info.district" filterable placeholder="区">
								<el-option label="五华区" value="2"></el-option>
						    </el-select><br>
							<el-select v-model="st_form.school_info.school" filterable placeholder="学校">
								<el-option label="xxx小学" value="3"></el-option>
						    </el-select>
						</el-form-item>
					</el-form>
					<div class="pull-right" style="width:150px;height:330px;">
						<el-steps direction="vertical" :active="active_step" process-status="wait">
						    <el-step v-for="step in step_opt" :key="step" :title="step"></el-step>
					  </el-steps>
					</div>
				</div>
			</el-card>
			<el-card class="el-card-box">
				<el-collapse>
					<el-collapse-item>
						<template slot="title">
							<h4>家长列表</h4>
						</template>
						<div class="el-card-body">
					<table class="table">
						<thead>
							<tr>
								<th class="text-center">姓名</th>
								<th class="text-center">联系方式</th>
								<th class="text-center">亲属关系</th>
								<th class="text-center">编辑</th>
							</tr>
						</thead>
						<tr align="center">
							<td>
								@{{parent_form.name}}
								<el-tag size="mini" type="warning">主要</el-tag>
							</td>
							<td>@{{parent_form.phone}}</td>
							<td>@{{parent_form.relation}}</td>
							<td>
								<el-button size="mini" type="success"
									plain circle icon="el-icon-edit"
									@click="editParent(parent_form)">
								</el-button>
							</td>
						</tr>
						<tbody>
							@foreach ($OtherParents as $other)
							<tr align="center">
								<td>{{$other['name']}}</td>
								<td>{{$other['phone']}}</td>
								<td>{{$other['relation']}}</td>
								<td>
									<el-button size="mini" type="success"
										plain circle icon="el-icon-edit"
										@click="editParent({{json_encode($other)}})">
									</el-button>
								</td>
							</tr>
							@endforeach
						</tbody>
					</table>
				</div>
					</el-collapse-item>
				</el-collapse>
			</el-card>
		</div>
		<div class="pull-right el-card-box-right">
			<el-card class="el-card-box">
				<div slot="header" class="el-card-header">
					<h4>主要家长</h4>
				</div>
				<div class="el-card-body">
					<el-form ref="primary_parent" :model="parent_form" :rules="parent_rules" label-width="80px" inline>
						<el-form-item label="姓名" prop="name">
							<el-input v-model="parent_form.name"></el-input>
						</el-form-item>
						<el-form-item label="联系方式" prop="phone">
							<el-input v-model="parent_form.phone"></el-input>
						</el-form-item>
						<el-form-item label="身份证" prop="id_card">
							<el-input v-model="parent_form.id_card"></el-input>
						</el-form-item>
						<el-form-item label="亲属关系" prop="relation">
							<el-select v-model="parent_form.relation" filterable>
								<el-option label="父亲" value="父亲"></el-option>
								<el-option label="母亲" value="母亲"></el-option>
								<el-option label="其他" value="其他"></el-option>
						    </el-select>
						</el-form-item>
					</el-form>
				</div>
			</el-card>
			<el-card class="el-card-box">
				<div slot="header" class="el-card-header">
					<h4>本次工单</h4>
				</div>
				<div class="el-card-body">
					<el-form ref="order_form" :model="order_form" :rules="order_rules" label-width="80px" class="order-form" inline>
						<el-form-item label="咨询方式" prop="ask_way">
							<el-select v-model="order_form.ask_way">
								<el-option label="电话咨询" value="电话咨询"></el-option>
								<el-option label="面咨" value="面咨"></el-option>
								<el-option label="其他" value="其他"></el-option>
						    </el-select>
						</el-form-item>
						<el-form-item label="工单类型" prop="ask_type">
							<el-select v-model="order_form.ask_type" filterable @change="handleSelectOrderType">
								<el-option label="电话咨询" value="电话咨询"></el-option>
								<el-option label="预约试听" value="预约试听"></el-option>
								<el-option label="试听记录" value="试听记录"></el-option>
								<el-option label="报名" value="报名"></el-option>
								<el-option label="二报通知" value="二报通知"></el-option>
								<el-option label="二报记录" value="二报记录"></el-option>
								<el-option label="开班学员分配" value="开班学员分配"></el-option>
								<el-option label="新班家长会通知" value="新班家长会通知"></el-option>
								<el-option label="新班家长会记录" value="新班家长会记录"></el-option>
								<el-option label="其他" value="其他"></el-option>
						    </el-select>
						</el-form-item>
						<el-form-item label="二级分类" prop="ask_type_s">
							<el-select v-model="order_form.ask_type_s">
								<el-option label="电话咨询" value="电话咨询"></el-option>
								<el-option label="面咨" value="面咨"></el-option>
								<el-option label="其他" value="其他"></el-option>
						    </el-select>
						</el-form-item>
						<el-form-item label="联系方式">
							<el-input  v-model="parent_form.phone" disabled></el-input>
						</el-form-item>
						<el-form-item label="亲属关系">
							<el-input  v-model="parent_form.relation" disabled></el-input>
						</el-form-item>
						<el-form-item label="预计回访" prop="expect_revisit">
							<el-select v-model="order_form.expect_revisit">
								<el-option label="暂不" value="暂不"></el-option>
								<el-option label="24小时" value="24小时"></el-option>
								<el-option label="3个工作日" value="3个工作日"></el-option>
								<el-option label="上级回复" value="上级回复"></el-option>
						    </el-select>
						</el-form-item>
						<el-form-item label="家长定级" prop="level">
							<el-select v-model="order_form.level" @change="handleSelectLevel">
								<el-option label="A" value="A"></el-option>
								<el-option label="B" value="B"></el-option>
								<el-option label="C" value="C"></el-option>
								<el-option label="D" value="D"></el-option>
						    </el-select>
						</el-form-item><br>
						<el-form-item label="态度描述">
							<el-checkbox-group v-model="order_form.attitude_opts" @change="handleChooseAttitude">
								<el-checkbox v-for="a in attitude_radios" :key="a" :label="a"></el-checkbox>
							</el-checkbox-group>
							<el-input
								class="input-new-tag"
								v-if="otherAttitudeInputVisible"
								v-model="otherAttitudeInputValue"
								ref="saveTagInput"
								size="small"
								placeholder="输入后回车添加选项"
								@change="handleChangeTagInput"
								@keyup.enter.native="handleOtherAttitudeConfirm"
								@blur="handleOtherAttitudeConfirm">
							</el-input>
							<el-button v-else class="button-new-tag" size="small" icon="el-icon-plus" @click="showOtherAttitudeInput">
								其它态度描述
							</el-button>
						</el-form-item><br>
						<el-form-item label="备注" prop="remark">
							<el-input type="textarea" v-model="order_form.remark"
								:autosize="{ minRows: 3, maxRows: 4}">
						 	</el-input>
						</el-form-item><br>
						<el-form-item label=" ">
							<el-button type="success" @click="doSubmit">提交修改信息及工单</el-button>
						</el-form-item>
					</el-form>
				</div>
			</el-card>
		</div>
	</el-row>
</div>
<input type="hidden" id="st-school-info" value="{{$StInfo['school_info']}}">
</body>
<script type="text/javascript">
let main = new Vue({
	el:"#main",
	data(){
		let checkPhone = (rule, value, callback) => {
			let rules = /^[1][1,2,3,4,5,6,7,8,9][0-9]{9}$/;
			if(!rules.test(value)){
				return callback(new Error('手机号格式不正确'));
			}else{
				callback();
			}
		};
		let checkIdCard = (rule, value, callback) => {
			let rules = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
			if(!rules.test(value)){
				return callback(new Error('身份证号格式不正确'));
			}else{
				callback();
			}
		};
		return {
			attitude_radios:['抠脚','骂脏话'],
			add_lvl_log:false,
			step:"{{$StInfo['step']}}",
			active_step:1,
			grade_opt:[],
			step_opt:['初始','试听','报名','二报','新班家长会','开班'],
			special_class:"not-show",
			lvl_log:[],
			st_form:{
				id:"{{$StInfo['id']}}",enroll_at:"{{$StInfo['enroll_at']}}",
				name:"{{$StInfo['name']}}",sex:"{{$StInfo['sex']}}",birthday:"{{$StInfo['birthday']}}",
				school_info:{stage:"",grade:"",city:"",district:"",school:"",special:"0"},
				lvl_log:"{{$StInfo['lvl_log']}}",level:"{{$StInfo['level']}}"
			},
			parent_form:{
				id:"{{$ParentInfo['id']}}",
				name:"{{$ParentInfo['name']}}",phone:"{{$ParentInfo['phone']}}",
				relation:"{{$ParentInfo['relation']}}",id_card:"{{$ParentInfo['id_card']}}",is_primary:"1"
			},
			order_form:{
				ask_way:"",ask_type:"",ask_type_s:"",
				level:"{{$StInfo['level']}}",attitude_opts:[],remark:""
			},
			other_form:{
				name:"",phone:"",relation:"",id_card:"",is_primary:"0"
			},
			st_rules:{
				name:[
					{required:true,message:'请填写姓名',trigger:['blur','change']},
					{min:2,max:45,message:'长度在2到45个字符',trigger:['blur','change']}
				],
				// sex:[{required:true,message:'请选择性别',trigger:['blur','change']}],
				// birthday:[{required:true,message:'请选择生日',trigger:['blur','change']}],
				// school_info:{
				// 	stage:[{required:true,message:'请选择在学阶段',trigger:['blur','change']}],
				// 	grade:[{required:true,message:'请选择年级',trigger:['blur','change']}],
				// 	school:[{required:true,message:'请选择学校',trigger:['blur','change']}],
				// }

			},
			parent_rules:{
				// name:[
				// 	{required:true,message:'请填写姓名',trigger:['blur','change']},
				// 	{min:2,max:45,message:'长度在2到45个字符',trigger:['blur','change']}
				// ],
				phone:[
					{required:true,message:'请填写联系方式',trigger:['blur','change']},
					{validator:checkPhone,trigger:['blur','change']},
				],
				// relation:[{required:true,message:'请选择亲属关系',trigger:['blur','change']}],
				// id_card:[
				// 	{required:true,message:'请填写身份证号',trigger:['blur','change']},
				// 	{validator:checkIdCard,trigger:['blur','change']},
				// ],
			},
			order_rules:{
				ask_way:[{required:true,message:'请选择',trigger:['blur','change']}],
				ask_type:[{required:true,message:'请选择',trigger:['blur','change']}],
				ask_type_s:[{required:true,message:'请选择',trigger:['blur','change']}],
				relation:[{required:true,message:'请选择',trigger:['blur','change']}],
				expect_revisit:[{required:true,message:'请选择',trigger:['blur','change']}],
				level:[{required:true,message:'请选择',trigger:['blur','change']}],
				remark:[{min:0,max:255,message:'长度在0到255个字符',trigger:['blur','change']}],
			},
			st_list_loading:false,
			show_st_list:false,
			seaForm:{
				_token:"{{csrf_token()}}",
				name:"",primary_phone:"",
				page:{
					pageNumber:1,pageSize:10,total:0
				}
			},
			st_list_data:[],
			show_other_form:false,
			otherAttitudeInputVisible:false,
			otherAttitudeInputValue:"",
			primary_disabled:false
		}
	},
	mounted:function() {
		this.initStForm();
		this.initStep();
		this.setSpecialOpt();
		this.setGrageOpt();
	},
	methods:{
		initStForm() {
			this.st_form.lvl_log = this.st_form.lvl_log.split(",");
			this.lvl_log = [].concat(this.st_form.lvl_log); // 避免引用
			let school_info = eval("("+$("#st-school-info").val()+")");
			this.st_form.school_info = school_info;
			if(this.st_form.school_info.stage == "1") {
				this.special_class = "show";
			}
		},
		initStep() {
			let length = this.step_opt.length;
			for(let i = 0;i<length;i++){
				if(this.step == this.step_opt[i]) {
					this.active_step = i + 1;
				}
			}
		},
		setGrageOpt() {
			switch (this.st_form.school_info.stage) {
				case "0":
					this.grade_opt = [{label:"学前",val:"0"}];
					break;
				case "1":
					this.grade_opt = [
						{label:"一年级",val:"1"},
						{label:"二年级",val:"2"},
						{label:"三年级",val:"3"},
						{label:"四年级",val:"4"},
						{label:"五年级",val:"5"},
						{label:"六年级",val:"6"}
					];
					this.special_class = "show";
					break;
				case "2":
					this.grade_opt = [
						{label:"初一",val:"7"},
						{label:"初二",val:"8"},
						{label:"初三",val:"9"}
					];
					break;
				case "3":
					this.grade_opt = [
						{label:"高一",val:"10"},
						{label:"高二",val:"11"},
						{label:"高三",val:"12"},
					];
					break;
				case "4":
					this.grade_opt = [
						{label:"其他",val:"13"}
					];
					break;
			}
		},
		setSpecialOpt() {
			if(this.st_form.school_info.special == "0"){
				this.grade_opt = [
					{label:"一年级",val:"1"},
					{label:"二年级",val:"2"},
					{label:"三年级",val:"3"},
					{label:"四年级",val:"4"},
					{label:"五年级",val:"5"},
					{label:"六年级",val:"6"}
				];
			}else{
				this.grade_opt = [
					{label:"一年级",val:"1"},
					{label:"二年级",val:"2"},
					{label:"三年级",val:"3"},
					{label:"四年级",val:"4"},
					{label:"五年级",val:"5"},
				];
			}
		},
		handleSelectStage() {
			this.st_form.school_info.grade = "";
			this.st_form.school_info.city = "";
			this.st_form.school_info.district = "";
			this.st_form.school_info.school = "";
			this.st_form.school_info.special = "0";
			this.special_class = "not-show";
			this.setGrageOpt();
		},
		handleSelectSpecial() {
			this.st_form.school_info.grade = "";
			this.setSpecialOpt();
		},
		handleSelectLevel() {
			this.st_form.lvl_log = [].concat(this.lvl_log); // 避免引用
			this.add_lvl_log = false;
			if(this.st_form.level != this.order_form.level) {
				this.add_lvl_log = true;
				let str = "{{date('Y-m-d')}}：{{$StInfo['level']}}" + "-" + this.order_form.level;
				str += " 更改人：{{Admin::user()->username}} 备注：" + this.order_form.attitude_opts.join("、");
				this.st_form.lvl_log.push(str);
			}
		},
		handleChooseAttitude() {
			if(this.add_lvl_log) {
				let str = "{{date('Y-m-d')}}：{{$StInfo['level']}}" + "-" + this.order_form.level + " 更改人：{{Admin::user()->username}} 备注：" + this.order_form.attitude_opts.join("、");
				this.st_form.lvl_log[this.st_form.lvl_log.length - 1] = str;
				this.st_form.lvl_log = [].concat(this.st_form.lvl_log); // 刷新循环数组,重新渲染
			}
		},
		handleSelectOrderType() {
			if(!this.st_form.enroll_at){
				if(this.order_form.ask_type == "报名"){
					this.st_form.enroll_at = "{{date('Y-m-d H:i:s')}}";
				}else{
					this.st_form.enroll_at = "";
				}
			}
		},
		showOtherAttitudeInput() {
			this.otherAttitudeInputVisible = true;
			this.$nextTick(_ => {
				this.$refs.saveTagInput.$refs.input.focus();
			});
		},
		handleOtherAttitudeConfirm() {
			let inputValue = this.otherAttitudeInputValue;
			if (inputValue) {
			  this.attitude_radios.push(inputValue);
			}
			this.otherAttitudeInputVisible = false;
			this.otherAttitudeInputValue = '';
		},
		handleChangeTagInput() {
			this.otherAttitudeInputValue = this.otherAttitudeInputValue.split(',').join('，');
		},
		doSubmit() {
			if(!this.checkForm()){
				return false;
			}
			let params = {
				_token:"{{csrf_token()}}",
				st:this.st_form,
				p:this.parent_form,
				o:this.order_form
			};
			let url = "{{URL::asset('admin/consultation/register/save')}}";
			$.post(url,params,function(res) {
				if(res.code == 1){
					window.location.href = "{{URL::asset('admin/consultation/register')}}?phone=" + res.data.phone + "&st_id=" + res.data.st_id;
				}else{
					main.$notify.error({title:"Error",message:res.msg});
				}
			});
		},
		checkForm() {
			let bool = true;
			this.$refs['st_form'].validate((valid) => {
				if (!valid) {
					bool = false;
				}
	        });
			this.$refs['primary_parent'].validate((valid) => {
				if (!valid) {
					bool = false;
				}
	        });
			this.$refs['order_form'].validate((valid) => {
				if (!valid) {
					bool = false;
				}
	        });
			return bool;
		},
		getStList() {
			let url = "{{URL::asset('admin/consultation/phone_consultation/get_all_st_table')}}";
			let param = this.seaForm;
			this.st_list_loading = true;
			$.get(url,param,function(res) {
				main.st_list_loading = false;
				main.st_list_data = res.data.rows;
				main.seaForm.page.total = res.data.total;
			});
		},
		showStList() {
			this.$refs['primary_parent'].validate((valid) => {
				if (valid) {
					this.show_st_list = true;
					this.getStList();
				}else{
					this.$notify.error({title:"Error",message:"请先完善家长信息"})
				}
	        });
		},
		pageSizeChange(val) {
			this.seaForm.page.pageSize = val;
			this.seaForm.page.pageNumber = 1;
			this.getStList();
		},
		curPageChange(val) {
			this.seaForm.page.pageNumber = val;
			this.getStList();
		},
		selectST(row) {
			let url = "{{URL::asset('admin/consultation/register/dolink')}}";
			let param = {
				_token:"{{csrf_token()}}",
				st_id:row.id,
				phone:this.parent_form.phone,
				name:this.parent_form.name,
				id_card:this.parent_form.id_card,
				relation:this.parent_form.relation,
				is_primary:this.is_primary
			}
			$.post(url,param,function(res) {
				if(res.code == 1){
					let uri = "{{URL::asset('admin/consultation/register')}}?phone="
					uri += res.data.primary_phone + "&st_id=" + row.id;
					window.location.href = uri;
				}else{
					main.$notify.error({title:"Error",message:res.msg});
				}
			});
		},
		editParent(other) {
			if(other.is_primary != "1"){
				other.is_primary = "0";
				this.primary_disabled = false;
			}else{
				this.primary_disabled = true;
			}
			other._token = "{{csrf_token()}}";
			other.st_id = this.st_form.id;
			this.other_form = other;
			this.show_other_form = true;
		},
		submitEdit() {
			this.$refs['other_parent'].validate((valid) => {
				if (valid) {
					let url = "{{URL::asset('admin/consultation/register/edit_parent')}}";
					let param = this.other_form;
					$.post(url,param,function(res) {
						if(res.code == 1){
							let uri = "{{URL::asset('admin/consultation/register')}}";
							uri += "?phone=" + res.data.phone;
							uri += "&st_id=" + res.data.st_id;
							window.location.href = uri;
						}else{
							main.$notify.error({title:"Error",message:res.msg});
						}
					});
				}
	        });
		}
	}
})
</script>
</html>
